s1 = '  Hello world  '

# 字符串t通用操作
print(s1 + 'hhh')
print(s1 * 3)
print(len(s1))
print(max(s1), min(s1))
print(ord('a'))  # asc码值
print(ord(' '))
# del s1

print('s' in s1)
print('abcd' < 'abce')
print('cd' < 'abcd')

print("*" * 20)
# 字符串的遍历
for i in s1:
    print(i)
for index, value in enumerate(s1):
    print(index, value)
for x in range(len(s1)):
    print(x, s1[x])

print("*" * 20)

# 类型转换
print(str(12), type(str(12)))  # int --> str
print(str([1, 2, 3, 4]), type(str([1, 2, 3, 4])))  # list --> str
print(str((1,)), type(str((1,))))  # tuple --》 str
print("*" * 20)
# 常用方法
print(s1.lower())
print(s1.upper())
print(s1.index('w'))  # 元素的索引
print(s1.count('o'))
print(s1.strip())  # 去除前后空格
print(s1.split(" "))  # 分割
print(s1.find("o", 5))  # 找索引，多个参数：查找开始位置
print('#'.join(['1', '2', '3', '4']))  # 1#2#3#4 链接字符串
print(s1.replace('o', '@'))

# 计算字符串中数字、字母、字符的个数
words = 'adddf,4122,ddd$$ddff84'
a, b, c = 0, 0, 0
for m in words:
    if m.isdigit():
        a += 1
    elif m.isalpha():
        b += 1
    else:
        c += 1
